package sz.szsmk.citizencard.face;

import android.graphics.Bitmap;
import android.os.Build;
import android.os.Bundle;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.squareup.okhttp.Request;
import com.zhy.http.okhttp.callback.StringCallback;

import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import sz.szsmk.citizencard.R;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.Constant;

public class ResultFragment extends FaceFragment{

    private ImageView mResultImageView = null;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_result_page, container, false);
        mResultImageView = (ImageView) view.findViewById(R.id.img_result);
        return view;
    }


//    private void toUpData(String base64) {
//        String access_token = ACache.get(getActivity()).getAsString("access_token");
//        com.zhy.http.okhttp.OkHttpUtils.post()
//                .url("https://newapptest.szsmk.com/app/uums/faceRecognition")
//                .addParams("access_token", access_token)
//                .addParams("actual_name", "张东昊")
//                .addParams("id_no", "411426199312074214")
//                .addParams("photo", base64)
//                .build()
//                .execute(new StringCallback() {
//
//                    @Override
//                    public void onError(Request call, Exception e) {
//                        L.e(Constant.TAG, "请求错误.." + e.getMessage());
//                    }
//
//                    @Override
//                    public void onResponse(String response) {
//
//                        L.e(Constant.TAG, "人脸识别请求结果：" + response);
//                    }
//                });
//    }

    @Override
    public void onResume() {
        super.onResume();

    }

    /**
     * 得到bitmap的大小
     */
    public static int getBitmapSize(Bitmap bitmap) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {    //API 19
            return bitmap.getAllocationByteCount();
        }
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) {//API 12
            return bitmap.getByteCount();
        }
        // 在低版本中用一行的字节x高度
        return bitmap.getRowBytes() * bitmap.getHeight();
    }


    public String Bitmap2StrByBase64(Bitmap bit) {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        bit.compress(Bitmap.CompressFormat.JPEG, 40, bos);//参数100表示不压缩
        byte[] bytes = bos.toByteArray();
        return Base64.encodeToString(bytes, Base64.DEFAULT);
    }

    private void saveBitmapToFile(Bitmap var0, String var1) {
        try {
            File var3;
            if ((var3 = new File(var1)).exists() || !var3.getParentFile().mkdirs() || var3.createNewFile()) {
                BufferedOutputStream var4 = new BufferedOutputStream(new FileOutputStream(var3));
                var0.compress(Bitmap.CompressFormat.JPEG, 80, var4);
                var4.close();
            }
        } catch (IOException var2) {
            var2.printStackTrace();
        }
    }
}